﻿#include "unstackplatesettingwid.h"
#include "ui_unstackplatesettingwid.h"
#include "cfgjsonrw.h"

UnstackPlateSettingWid::UnstackPlateSettingWid(QWidget *parent)
	: QWidget(parent)
	, ui(new Ui::UnstackPlateSettingWid())
{
	ui->setupUi(this);
	setStyleSheet("font: 12pt \"Agency FB\"");
}

UnstackPlateSettingWid::~UnstackPlateSettingWid()
{
	delete ui;
}

void UnstackPlateSettingWid::Init(const UnstackPlateCfg& cfg)
{
	ui->lineEdit->setText(cfg.id());
	on_pushButton_clicked();
	ui->comboBox->setCurrentText(cfg.camera());
	ui->comboBox_2->setCurrentIndex(cfg.dir());
	ui->spinBox->setValue(cfg.max());
	
}

UnstackPlateCfg UnstackPlateSettingWid::GetCfg()
{
	UnstackPlateCfg cfg = {};
	cfg.id = ui->lineEdit->text();
	cfg.camera = ui->comboBox->currentText();
	cfg.dir = ui->comboBox_2->currentIndex();
	cfg.max = ui->spinBox->value();
	return cfg;
}


void UnstackPlateSettingWid::on_pushButton_clicked()
{
	auto cfg = cfgrw->GetCameraCfg();
	QStringList cams;
	for (auto& iter : cfg.cameras()) {
		cams.append(iter.id());
	}

	ui->comboBox->clear();
	ui->comboBox->addItems(cams);
}
